﻿namespace MvcXRepairAdmin.Controllers
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Mvc;
    using MvcXRepairAdmin.Interfaces;
    using MvcXRepairAdmin.Services;
    using XRepair.Models;

    public class SymptomController : BaseController
    {
        private ISymptomService _symptomService;

        public SymptomController()
        {
            _symptomService = new SymptomService();
        }

        public ActionResult Index()
        {
            IEnumerable<Symptom> symptoms = _symptomService.GetAllActiveSymptoms();
            //List<Symptom> model = symptoms.ToList();
            List<Symptom> model = symptoms != null ? symptoms.ToList() : new List<Symptom>();
            return View(model);
        }

        public ActionResult Delete(int id)
        {
            bool succeed = _symptomService.DeactivateSymptomByID(id);

            if (succeed)
            {
                return RedirectToAction("Index");
            }

            return RedirectToAction("ErrorOnProcessing", "Error");
        }

        public ActionResult AddNew(Symptom model)
        {
            bool succeed = _symptomService.AddNewSymptom(model);

            if (succeed)
            {
                return RedirectToAction("Index");
            }

            return RedirectToAction("ErrorOnProcessing", "Error");
        }

        public ActionResult Edit(Symptom model)
        {
            model.IsActive = true;
            bool succeed = _symptomService.EditSymptom(model);

            if (succeed)
            {
                return RedirectToAction("Index");
            }

            return RedirectToAction("ErrorOnProcessing", "Error");
        }
    }
}
